import echarts from 'echarts/lib/echarts'
// 引入柱状图
import 'echarts/lib/chart/bar'
// 引入提示框和标题组件
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
const setChart = (chart, {
  value,
  arg
}) => {
  if (arg === 'loading') chart.showLoading()
  else chart.hideLoading()
  chart.setOption(value)
}
export const charts = {
  inserted(el, binding) {
    const chart = echarts.init(el);
    window.addEventListener('resize', chart.resize)
    setChart(chart, binding)
  },
  update(el, binding) {
    const chart = echarts.getInstanceByDom(el)
    setChart(chart, binding)
  },
  unbind(el) {
    const chart = echarts.init(el);
    chart.dispose(el);
    window.removeEventListener('resize', chart.resize)
  }
}